<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/pages/common/taglib.jsp"%>
<script src="/hztgweb/resource/My97DatePicker/WdatePicker.js"></script>
<script language="javascript">
	String.prototype.trim=function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
	
	function tj(){
		if(checkBsx()){
			if(checkGs()){
				if(checkZjs()){
					if(confirm("是否确定提交以上数据?")){
						document.getElementById("add_submit").disabled = "disabled";
						document.getElementById("id_addform").submit();
					}
				}
			}
		}
	}

	function checkBsx(){
		var sex = document.getElementsByName("usersex");
		var i;
		for(i=0; i<sex.length;i++){
			if(sex[i].checked){
				document.getElementById("usersex").value = encodeURIComponent(sex[i].value);
			}
		}
		if (document.getElementById("username").value.trim()==null||document.getElementById("username").value.trim()==""){
	             alert('请输入姓名！');
	             document.getElementById("username").focus();
	             return false;
	    }
	    else if (document.getElementById("userpwd").value.trim()==null||document.getElementById("userpwd").value.trim()==""){
	             alert('请输入密码！');
	             document.getElementById("userpwd").focus();
	             return false;
	    }
	    else if (document.getElementById("userrepwd").value.trim()==null||document.getElementById("userrepwd").value.trim()==""){
	             alert('请输入确认密码！');
	             document.getElementById("userrepwd").focus();
	             return false;
	    }
		else if (document.getElementById("usersex").value==null||document.getElementById("usersex").value==""){
				 alert('请选择性别！');
				 return false;
		}
	   	else if (document.getElementById("userbirth").value.trim()==null||document.getElementById("userbirth").value.trim()==""){
	             alert('请输入出生年月！');
	             document.getElementById("userbirth").focus();
	             return false;
	    }
	    else if ((document.getElementById("usertel").value.trim()==null||document.getElementById("usertel").value.trim()=="")){
	             alert('请输入联系电话！');
	             document.getElementById("usertel").focus();
	             return false;
	    }
	    else if ((document.getElementById("usermobile").value.trim()==null||document.getElementById("usermobile").value.trim()=="")){
	             alert('请输入手机号码！');
	             document.getElementById("usermobile").focus();
	             return false;
	    }
	    else if ((document.getElementById("useraddress").value.trim()==null||document.getElementById("useraddress").value.trim()=="")){
	             alert('请输入家庭详细住址！');
	             document.getElementById("useraddress").focus();
	             return false;
	    }
	    else if (document.getElementById("usermail").value.trim()==null||document.getElementById("usermail").value.trim()==""){
	             alert('请输入邮编！');
	             document.getElementById("usermail").focus();
	             return false;
	    } 
	    else if (document.getElementById("usercomp").value.trim()==null||document.getElementById("usercomp").value.trim()==""){
           	 	alert('请输入工作单位！');
            	document.getElementById("usercomp").focus();
           		return false;
   		}
   		else if (document.getElementById("userrepwd").value!=document.getElementById("userpwd").value){
   				alert('确认密码和密码不符！');
   				document.getElementById("userrepwd").focus();
   				return false;
   		}
	    else{
	   			return true;
	    }	
	}
	
	//格式校验
	function checkGs(){
		var sfzh = document.getElementById("useridcard").value;
		var pwd = document.getElementById("userpwd").value;
		var repwd = document.getElementById("userrepwd").value;
		var tel = document.getElementById("usertel").value;
		var mailvalue = document.getElementById("usermail").value;
		var mobile = document.getElementById("usermobile").value;
		//var pattern = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	    if (isChinese(sfzh)){
	             alert('身份证号不应有汉字！');
	             document.getElementById("useridcard").focus();
	             return false;
	    }
	    else if (isChinese(pwd)){
	             alert('密码不应有汉字！');
	             document.getElementById("userpwd").focus();
	             return false;
	    }
	    else if (isChinese(repwd)){
	             alert('确认密码不应有汉字！');
	             document.getElementById("userrepwd").focus();
	             return false;
	    }
	    else if (isNaN(tel)){
	             alert('联系电话只能填写数字！');
	             document.getElementById("usertel").focus();
	             return false;
	    }
	    else if (isNaN(mobile)){
	             alert('手机号码只能填写数字！');
	             document.getElementById("usermobile").focus();
	             return false;
	    }
	    else if (isNaN(mailvalue)){
	             alert("请输入有效的邮编！");
	             document.getElementById("usermail").focus();
	             return false;
	    } 
	    else{
	   			 return true;
	    }	
	}	
	
	function isChinese(name){  
		if(name.length==0){
			return  false;
		}
		for(i=0;i<name.length;i++){  
			if(name.charCodeAt(i) > 128)
			return  true;
		}
		return false;
	}
	
	function checkZjs(){
		var username = document.getElementById("username").value;
		var usernamezjs = username.replace(/[^\x00-\xff]/g,'**').length;
		
		var userpwd = document.getElementById("userpwd").value;
		var userpwdzjs = userpwd.replace(/[^\x00-\xff]/g,'**').length;
		
		var useridcard = document.getElementById("useridcard").value;
		var useridcardzjs = useridcard.replace(/[^\x00-\xff]/g,'**').length;

		var useraddress = document.getElementById("useraddress").value;
		var useraddresszjs = useraddress.replace(/[^\x00-\xff]/g,'**').length;
		
		var usermail = document.getElementById("usermail").value;
		var usermailzjs = usermail.replace(/[^\x00-\xff]/g,'**').length;
		
		var usercomp = document.getElementById("usercomp").value;
		var usercompzjs = usercomp.replace(/[^\x00-\xff]/g,'**').length;

		if (username!=null&&username!=""&&usernamezjs>30){
	             alert("姓名输入过大，请重新填写！");
	             document.getElementById("username").focus();
	             return false;
	    }
	    else if (userpwd!=null&&userpwd!=""&&(userpwdzjs>18||userpwdzjs<6)){
	             alert("密码输入不正确，请重新填写！");
	             document.getElementById("new_userpwd").focus();
	             return false;
	    }
	    else if (useridcard!=null&&useridcard!=""&&(useridcardzjs!=15&&useridcardzjs!=18)){
	             alert("身份证输入不正确，请重新填写！"+useridcardzjs);
	             document.getElementById("useridcard").focus();
	             return false;
	    }
	    else if (useraddress!=null&&useraddress!=""&&useraddresszjs>30){
	             alert("家庭详细地址输入过大，请重新填写！");
	             document.getElementById("useraddress").focus();
	             return false;
	    }
	    else if (usermail!=null&&usermail!=""&&usermailzjs>9){
	             alert("邮编输入过大，请重新填写！");
	             document.getElementById("usermail").focus();
	             return false;
	    }
	    else if (usercomp!=null&&usercomp!=""&&usercompzjs>30){
	             alert("工作职责输入过大，请重新填写！");
	             document.getElementById("usercomp").focus();
	             return false;
	    }
	    else{
	   			 return true;
	    }	
	}
</script>
<div class="register_form">
<s:form id="id_addform" name="addform" action="add" method="post" namespace="/register">
  <p><label>身份证号码：</label><span>*</span>
  <input type="text" name="useridcard" id="useridcard" value="<s:property value='useridcard'/>" class="inp text1"/><span class="wenzi">为登录账号</span>
  </p>
  <p><label>姓名：</label><span>*</span>
  <input type="text" name="username" id="username" value="<s:property value='username'/>" class="inp text1" /><span class="wenzi">请输入真实姓名</span></p>
  <p><label>密码：</label><span>*</span>
  <input type="password" name="userpwd" id="userpwd" value="<s:property value='userpwd'/>" class="inp text1"/><span class="wenzi">密码范围6~18个字符，不包含汉字！</span></p>
  <p><label>确认密码：</label><span>*</span>
  <input type="password" name="userrepwd" id="userrepwd" value="" class="inp text1"/>
  </p>
  <p><label>性别：</label><span>*</span>
  <input type="radio" name="usersex" value="男"/><em>男</em>
  <input type="radio" name="usersex" value="女"/><em>女</em>
  </p>
  <p><label>出生年月：</label><span>*</span>
  <input name="userbirth" id="userbirth" type="text" class="inp text1" onfocus="new WdatePicker(this,'%Y-%M-%D',true);" value="<s:property value='userbirth'/>"/><span class="wenzi">格式YYYY-MM-DD</span></p>
  <p><label>联系电话：</label><span>*</span>
  <input type="text" name="usertel" id="usertel" value="<s:property value='usertel'/>" class="inp text1"/>
  </p>
  <p>
    <label>手机：</label><span>*</span>
    <input type="text" name="usermobile" id="usermobile" value="<s:property value='usermobile'/>" class="inp text1"/><span class="wenzi">请输入长期使用的手机号码</span></p>
  <p><label>家庭详细地址：</label><span>*</span>
    <input type="text" name="useraddress" id="useraddress" value="<s:property value='useraddress'/>" class="inp text2"/></p>
  <p>
    <label>邮编：</label><span>*</span>
    <input type="text" name="usermail" id="usermail" value="<s:property value='usermail'/>" class="inp text1"/></p>
  <p>
    <label>工作职责：</label><span>*</span>
    <input type="text" name="usercomp" id="usercomp" value="<s:property value='usercomp'/>" class="inp text1"/>
  </p>
  <p>
	<input type="button" id="add_submit" name="add_submit" value="提 交"  class="button img1" onClick="tj();"/>
  </p>

</s:form>
</div>